-- wear_heal
-- create by zhuangsl
-- 首次穿戴时，属性回复xx%

return {
    apply = function(prop, baseValue)
        -- 提升的值
        return baseValue + math.modf(baseValue * prop[3] / 1000);
    end,

    record = function(target, prop, path)
        return false;
    end,

    -- 穿戴装备触发
    trigger = function(who, prop, classId)
        local attrib = prop[2];
        local propId = tonumber(prop[1]);

        assert(attrib == "hp" or attrib == "mp", "只有生命值和魔法值才能按百分比恢复。");

        -- 预先处理一下
        if not EquipM.doWearTrigger(who, classId, propId, attrib) then
            return 0;
        end

        local maxAttrib = who:queryAttrib("max_" .. attrib);
        local v = math.modf(maxAttrib * tonumber(prop[3]) / 1000);

        v = math.min(maxAttrib - who:queryAttrib(attrib), v);

        who:addAttrib(attrib, v, "wear_heal");

        return v;
    end,
};
